package v2

import (
	rpcv1 "gluenet/internal/agent/api/rpc/v1"
	corev1 "gluenet/pkg/agent/types"
	"gluenet/pkg/agent/v2/rpc"
)

type MaasGetter interface {
	Maas() GluenetMaasInterface
}

type GluenetMaasInterface interface {
	BootResourcesSearch(maasReq *corev1.MaasReq) (result []byte, err error)
	SubNetsSearch(maasReq *corev1.MaasReq) (result []byte, err error)
	VMHostSearch(maasReq *corev1.MaasReq) (result []byte, err error)
	VMHostsSearch(maasReq *corev1.MaasReq) (result []byte, err error)
	VMHostsCreate(maasReq *corev1.MaasReq) (result []byte, err error)
	VMHostsDelete(maasReq *corev1.MaasReq) (result []byte, err error)
	MachineCreate(maasReq *corev1.MaasReq) (result []byte, err error)
	MachineDelete(maasReq *corev1.MaasReq) (result []byte, err error)
	MachineUpdate(maasReq *corev1.MaasReq) (result []byte, err error)
	MachineSearch(maasReq *corev1.MaasReq) (result []byte, err error)
	MachinesSearch(maasReq *corev1.MaasReq) (result []byte, err error)
	MachinePowerOn(maasReq *corev1.MaasReq) (result []byte, err error)
	MachinePowerOff(maasReq *corev1.MaasReq) (result []byte, err error)
	MachineDetails(maasReq *corev1.MaasReq) (result []byte, err error)
	TagsUpdateNodes(maasReq *corev1.MaasReq) (result []byte, err error)
	MachineDeploy(maasReq *corev1.MaasReq) (result []byte, err error)
	SubNetsIPAddressesSearch(maasReq *corev1.MaasReq) (result []byte, err error)
}

type gluenetMaas struct {
	client rpc.Interface
}

func newGluenetMaas(c *CoreClient) *gluenetMaas {
	return &gluenetMaas{
		client: c.RPCClient(),
	}
}

func (c *gluenetMaas) BootResourcesSearch(maasReq *corev1.MaasReq) (result []byte, err error) {
	err = c.client.Invoke().
		Api(rpcv1.MaasBootResourcesSearch).
		Spec(*maasReq).
		Do().
		Into(&result)
	return
}

func (c *gluenetMaas) SubNetsSearch(maasReq *corev1.MaasReq) (result []byte, err error) {
	err = c.client.Invoke().
		Api(rpcv1.MaasSubnetsSearch).
		Spec(*maasReq).
		Do().
		Into(&result)
	return
}

func (c *gluenetMaas) VMHostSearch(maasReq *corev1.MaasReq) (result []byte, err error) {
	err = c.client.Invoke().
		Api(rpcv1.MaasVmHostSearch).
		Spec(*maasReq).
		Do().
		Into(&result)
	return
}

func (c *gluenetMaas) VMHostsSearch(maasReq *corev1.MaasReq) (result []byte, err error) {
	err = c.client.Invoke().
		Api(rpcv1.MaasVmHostsSearch).
		Spec(*maasReq).
		Do().
		Into(&result)
	return
}
func (c *gluenetMaas) VMHostsCreate(maasReq *corev1.MaasReq) (result []byte, err error) {
	err = c.client.Invoke().
		Api(rpcv1.MaasVmHostsCreate).
		Spec(*maasReq).
		Do().
		Into(&result)
	return
}

func (c *gluenetMaas) VMHostsDelete(maasReq *corev1.MaasReq) (result []byte, err error) {
	err = c.client.Invoke().
		Api(rpcv1.MaasVmHostsDelete).
		Spec(*maasReq).
		Do().
		Into(&result)
	return
}

func (c *gluenetMaas) MachineCreate(maasReq *corev1.MaasReq) (result []byte, err error) {
	err = c.client.Invoke().
		Api(rpcv1.MaasMachineCreate).
		Spec(*maasReq).
		Do().
		Into(&result)
	return
}

func (c *gluenetMaas) MachineDelete(maasReq *corev1.MaasReq) (result []byte, err error) {
	err = c.client.Invoke().
		Api(rpcv1.MaasMachineDelete).
		Spec(*maasReq).
		Do().
		Into(&result)
	return
}

func (c *gluenetMaas) MachineUpdate(maasReq *corev1.MaasReq) (result []byte, err error) {
	err = c.client.Invoke().
		Api(rpcv1.MaasMachineUpdate).
		Spec(*maasReq).
		Do().
		Into(&result)
	return
}

func (c *gluenetMaas) MachineSearch(maasReq *corev1.MaasReq) (result []byte, err error) {
	err = c.client.Invoke().
		Api(rpcv1.MaasMachineSearch).
		Spec(*maasReq).
		Do().
		Into(&result)
	return
}

func (c *gluenetMaas) MachinesSearch(maasReq *corev1.MaasReq) (result []byte, err error) {
	err = c.client.Invoke().
		Api(rpcv1.MaasMachinesSearch).
		Spec(*maasReq).
		Do().
		Into(&result)
	return
}

func (c *gluenetMaas) MachinePowerOn(maasReq *corev1.MaasReq) (result []byte, err error) {
	err = c.client.Invoke().
		Api(rpcv1.MaasMachinePowerOn).
		Spec(*maasReq).
		Do().
		Into(&result)
	return
}

func (c *gluenetMaas) MachinePowerOff(maasReq *corev1.MaasReq) (result []byte, err error) {
	err = c.client.Invoke().
		Api(rpcv1.MaasMachinePowerOff).
		Spec(*maasReq).
		Do().
		Into(&result)
	return
}

func (c *gluenetMaas) MachineDetails(maasReq *corev1.MaasReq) (result []byte, err error) {
	err = c.client.Invoke().
		Api(rpcv1.MaasMachineDetails).
		Spec(*maasReq).
		Do().
		Into(&result)
	return
}

func (c *gluenetMaas) TagsUpdateNodes(maasReq *corev1.MaasReq) (result []byte, err error) {
	err = c.client.Invoke().
		Api(rpcv1.MaasTagsUpdateNodes).
		Spec(*maasReq).
		Do().
		Into(&result)
	return
}

func (c *gluenetMaas) MachineDeploy(maasReq *corev1.MaasReq) (result []byte, err error) {
	err = c.client.Invoke().
		Api(rpcv1.MaasMachineDeploy).
		Spec(*maasReq).
		Do().
		Into(&result)
	return
}

func (c *gluenetMaas) SubNetsIPAddressesSearch(maasReq *corev1.MaasReq) (result []byte, err error) {
	err = c.client.Invoke().
		Api(rpcv1.MaasSubnetsIPAddressesSearch).
		Spec(*maasReq).
		Do().
		Into(&result)
	return
}
